; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s

declare ptr @realloc(ptr allocptr, i64) allockind("realloc") allocsize(1)
declare noalias ptr @malloc(i64) allockind("alloc,uninitialized")


define ptr @realloc_null_ptr() #0 {
; CHECK-LABEL: @realloc_null_ptr(
; CHECK-NEXT:    [[MALLOC:%.*]] = call dereferenceable_or_null(100) ptr @malloc(i64 100)
; CHECK-NEXT:    ret ptr [[MALLOC]]
;
  %call = call ptr @realloc(ptr null, i64 100) #2
  ret ptr %call
}

define ptr @realloc_unknown_ptr(ptr %ptr) #0 {
; CHECK-LABEL: @realloc_unknown_ptr(
; CHECK-NEXT:    [[CALL:%.*]] = call dereferenceable_or_null(100) ptr @realloc(ptr [[PTR:%.*]], i64 100)
; CHECK-NEXT:    ret ptr [[CALL]]
;
  %call = call ptr @realloc(ptr %ptr, i64 100) #2
  ret ptr %call
}
